#include <bits/stdc++.h>
#define rp(i, l, r) for(int i = l; i <= r; i++)
using namespace std;

int readint() {
	int x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar();}
	while(ch >='0' && ch <= '9') { x = x * 10 + (ch - '0'); ch = getchar();}
	return f * x;
}
const int MAXN = 100010;
int T, n, m, L, V, flag = 0;
struct car {
	int d, v, a;
}car[MAXN];
int det[MAXN];

namespace subtask2{
void solve() {
	int cnt = 0;
	rp(i, 1, n) {
		if(car[i].d <= det[m] && car[i].v > V) {
			cnt++;
		}
	}
	if(cnt > 0) {
		printf("%d %d\n", cnt, m - 1);
	}
	else {
		printf("%d %d\n", 0, m);
	}
}
}

namespace subtask1 {
const int MAXM = 35;
vector < int > g[MAXM];
bool spd[MAXM];
bool op[MAXM];
bool tick[MAXM];
bool ok;
int opcnt, spdcnt;
bool speed(int x, int y) {
	if(car[x].v * car[x].v + 2 * car[x].a * (det[y] - car[x].d) > V * V) return 1;
	else return 0;
}
void dfs(int now, int cnt) {
	if(now == m + 1) {
		rp(i, 1, n) tick[i] = 0;
		rp(i, 1, m) {
			if(op[i] == 1) {
				for(int j : g[i]) {
					tick[j] = 1;
				}
			}
		}
		ok = 1;
		rp(i, 1, n) {
			if(spd[i] == 1 && tick[i] == 0) {
				ok = 0;
				break;
			}
		}
		if(ok == 1) {
			opcnt = min(opcnt, cnt);
		}
		return;
	}
	if(cnt > opcnt) return;
	op[now] = 0;
	dfs(now + 1, cnt);
	op[now] = 1;
	dfs(now + 1, cnt + 1);
}
void clear() {
	opcnt = m;
	spdcnt = 0;
	rp(i, 1, m) {
		g[i].clear();
		op[i] = 0;
	}
	rp(i, 1, n) {
		spd[i] = 0;
	}
}
void solve() {
	clear();
	rp(i, 1, n) {
		rp(j, 1, m) {
			if(det[j] >= car[i].d && speed(i, j) == 1) {
				spd[i] = 1;
				g[j].push_back(i);
			}
		}
	}
	rp(i, 1, n) {
		if(spd[i] == 1) spdcnt++;
	}
	dfs(1, 0);
	printf("%d %d\n", spdcnt, m - opcnt);
}
}

namespace subtask3{
int spdid[MAXN];
int spdcnt;
bool speed(int x, int y) {
	if(car[x].v * car[x].v + 2 * car[x].a * (det[y] - car[x].d) > V * V) return 1;
	else return 0;
}
bool check(int i, int id) {
	if(det[id] < car[i].d) return 0;
	if(speed(i, id) == 1) return 1;
	else return 0;
} 
int spdcnt2 = 0;
bool cmp(int a, int b) {
	return a > b;
}
void solve() {
	spdcnt = 0;
	spdcnt2 = 0;
	rp(i, 1, n)spdid[i] = 0;
	int ans = 0;
	rp(i, 1, n) {
		int l = 1, r = m, mid = 0;
		while(l <= r) {
			mid = (l + r) / 2;
			if(check(i, mid) == 1) {
				r = mid - 1;
			}
			else l = mid + 1;
			//cout<<l<<' '<<r<<endl;
		}//puts("YES");
		rp(j, max(1, mid-3), min(m,mid + 3)) {
			if(check(i, j)) {
				spdcnt++;
				spdid[i] = j; //excellent
				break;
			}
		}
	}
	sort(spdid + 1, spdid + n + 1, cmp);
	if(spdcnt > 0) {
	printf("%d %d\n", spdcnt, m - 1);
	}
	else printf("%d %d\n", spdcnt, m);
}
}
namespace subtask4{
int spdid[MAXN];
int spdcnt;
bool speed(int x, int y) {
	if(car[x].v * car[x].v + 2 * car[x].a * (det[y] - car[x].d) > V * V) return 1;
	else return 0;
}
bool check(int i, int id) {
	if(det[id] < car[i].d) return 0;
	if(speed(i, id) == 1) return 1;
	else return 0;
} 
int spdcnt2 = 0;
bool cmp(int a, int b) {
	return a > b;
}
void solve() {
	spdcnt = 0;
	spdcnt2 = 0;
	rp(i, 1, n)spdid[i] = 0;
	//int ans = 0;
	rp(i, 1, n) {
		int l = 1, r = m, mid;
		while(l <= r) {
			mid = (l + r) / 2;
			if(check(i, mid) == 1) {
				r = mid - 1;
			}
			else l = mid + 1;
			//cout<<l<<' '<<r<<endl;
		}//puts("YES");
		rp(j, max(1, mid-3), min(m,mid + 3)) {
			if(check(i, j)) {
				spdcnt++;
				spdid[i] = j; //excellent
				break;
			}
		}
	}
	sort(spdid + 1, spdid + n + 1, cmp);
	if(spdcnt== 0) {
		printf("%d %d\n", spdcnt, 0);
	}
	else printf("%d %d\n", spdcnt, m);
}
}
int flaga = 0;
int main() {
	freopen("detect.in", "r", stdin);
	freopen("detect.out", "w", stdout);
	T = readint();
	while(T--) {
		n = readint(), m = readint(), L = readint(), V = readint();
		flag = 2;
		flaga = 3;
		rp(i, 1, n) {
			car[i].d = readint(), car[i].v = readint(), car[i].a = readint();
			if(car[i].a != 0) flag = 0;
			if(car[i].a <= 0) flaga = 0;
		}
		rp(i, 1, m) {
			det[i] = readint();
		}
		if(flag == 2) {
			subtask2::solve();
		}
		else if(n <= 20 && m <= 20) {
			subtask1::solve();
		}
		else if(flaga == 3) {
			subtask3::solve();
		}
		else subtask4::solve();
	}
	return 0;
}
